home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM 1
/
LIGHT-ROM 1 (Amiga Library Services)(1994).iso
/
ffdisks
/
d954.lha
/
SCAN8800
/
Example_in_C
/
SCAN8800_1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-27
|
9KB
|
322 lines
/**************************************************************************/
/*** Programmname: "SCAN8800_1.c" MIF-90 ***/
/*** Update : vom 17.02.91 ***/
/*** Beschreibung: Simple Steuerung des Empfängers FRG-8800 von YAESU ***/
/*** über das Interface MINIX MIF-90. ***/
/*** Autor : Rainer Redweik Kattowitzer Str. 7 D-3180 Wolfsburg 1***/
/*** Version : 1.0 ***/
/*** Computer : AMIGA 500/1000/2000/3000T mit Kickstart 1.3/2.0 ***/
/*** Compiler : Aztec C V-5.0 with precompiled includefiles ***/
/*** : cc -ff -ps -so -wp -wu -hiInclude16.pre SCAN8800_1.c ***/
/*** : ln SCAN8800_1.o +q -lmf16 -lc16 ***/
/**************************************************************************/
#include <functions.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WARTE 200L
#define UNIT_NUMBER 0L /* Multiple serial port */
#define SER_BUFFER_SIZE 6
/** TEXT --> unsigned char **/
/***************PROTOTYPES***********************************************/
void oeffnen(void);
void schliessen(void);
void Serial_Read(void);
void Serial_Write(void);
LONG Freq_to_Buffer(LONG);
void Set_Freq(LONG);
/***************STRUCTUREN***********************************************/
struct MsgPort *SerialMP = 0L; /* Für serial.device */
struct IOExtSer *SerialIO = 0L; /* Für serial.device */
/********************VARIABLE********************************************/
TEXT SerialBuffer[SER_BUFFER_SIZE] = "";
LONG OpenDevErr = -1;
/********************FUNCTIONEN******************************************/
void main(void)
{
LONG i;
oeffnen();
printf("\fBaud: %ld\n\n", SerialIO->io_Baud);
/* Fernb. ON */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x00,0x00);
Serial_Write();
Serial_Write(); /* Zur Sicherheit zweimal senden */
/* Netz ON */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0xfe,0x80);
Serial_Write();
/* AM wide */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x00,0x80);
Serial_Write();
Set_Freq(14254000L);
Delay(WARTE);
printf("\n\n Scan MW with 9 kHz step\n");
for(i = 522000; i <= 1611000L; i+=9000L) /* Scan MW with 9 KHz step */
Set_Freq(i);
printf("\n\nScan part of MW with 25 Hz step\n");
for(i = 1466500L; i <= 1467500L; i+=25L) /* Scan part of MW with 25 Hz step */
{
Set_Freq(i);
Delay(10L);
}
Delay(WARTE);
printf("\f10 MHz AM - wide:\n");
Set_Freq(10000000L);
Delay(WARTE);
printf("\f10 MHz AM - narr\n");
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x08,0x80);
Serial_Write();
Delay(WARTE);
printf("\f10 MHz LSB\n");
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x01,0x80);
Serial_Write();
Delay(WARTE);
printf("\f10 MHz CW - narr\n");
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x0b,0x80);
Serial_Write();
Delay(WARTE);
printf("\f10 MHz FM - narr\n");
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x0c,0x80);
Serial_Write();
Delay(WARTE);
printf("\f");
/* Netz OFF */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0xff,0x80);
Serial_Write();
printf("Empfänger auf 756 kHz einstellen.\n\n");
/* Laut Beschreibung 2x die Frequenz senden */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x56,0x07,0x00,0x01);
Serial_Write();
Serial_Write();
/* Fernb. OFF */
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", 0x01,0x01,0x01,0x80,0x00);
Serial_Write();
printf("Der Empfänger sollte laut Beschreibung auf dieser Freq. eingestellt bleiben!\n\n");
schliessen();
}/* main() end*/
void oeffnen(void)
{
if(!(SerialMP = CreatePort(0,0)))
{
printf("CreatePort failed \n");
schliessen();
}
if(!(SerialIO = (struct IOExtSer *)CreateExtIO(SerialMP, sizeof(struct IOExtSer))))
{
printf("CreateExtIO failed \n");
schliessen();
}
SerialIO->io_SerFlags = SERF_SHARED | SERF_XDISABLED;
if((OpenDevErr = OpenDevice(SERIALNAME, UNIT_NUMBER, (struct IORequest *)SerialIO, 0L)) != 0L)
{
printf("Open-Device Error #%4lx IOERR_OPENFAIL: %ld\n", OpenDevErr, (LONG)IOERR_OPENFAIL);
schliessen();
}
SerialIO->IOSer.io_Command = CMD_RESET;
SendIO((struct IORequest *)SerialIO);
SerialIO->IOSer.io_Command = SDCMD_SETPARAMS;
SerialIO->io_Baud = 4800L;
SerialIO->io_ReadLen = SerialIO->io_WriteLen = 8;
SerialIO->io_StopBits = 2;
SendIO((struct IORequest *)SerialIO);
}/* oeffnen() end */
void schliessen(void)
{
if(SerialIO)
{
if(OpenDevErr == 0L)
{
AbortIO ((struct IORequest *)SerialIO);
WaitIO ((struct IORequest *)SerialIO);
CloseDevice((struct IORequest *)SerialIO);
}
DeleteExtIO((struct IORequest *)SerialIO);
}
if(SerialMP) DeletePort((struct MsgPort*)SerialMP);
exit(0);
}/* schliessen() end */
void Serial_Read(void)
{
LONG Temp;
ULONG WaitMask = SIGBREAKF_CTRL_C | 1L << SerialMP->mp_SigBit;
/* Listing aus 'AMIGA ROMKERNEL Libraries&Devices Seite 863' */
SerialIO->IOSer.io_Command = CMD_READ;
SerialIO->IOSer.io_Length = SER_BUFFER_SIZE;
SerialIO->IOSer.io_Data = (APTR)&SerialBuffer[0];
SendIO((struct IORequest *)SerialIO);
while(1)
{
Temp = Wait(WaitMask);
if(SIGBREAKF_CTRL_C & Temp)
{
printf("Abbruch durch CTRL-C\n");
break;
}
if( CheckIO((struct IORequest *)SerialIO) )
{
WaitIO((struct IORequest *)SerialIO);
/* printf("%ld bytes received\n", SerialIO->IOSer.io_Actual);*/
break;
}
}
AbortIO((struct IORequest *)SerialIO);
WaitIO((struct IORequest *)SerialIO);
}/* Serial_Read() end */
void Serial_Write(void)
{
/*************************************************************************/
/* I am not glad about this part, but without this the programm dosn't */
/* work correct: only a few times of frequency-changes are possible. */
SerialIO->IOSer.io_Command = CMD_RESET;
DoIO((struct IORequest *)SerialIO);
SerialIO->IOSer.io_Command = SDCMD_SETPARAMS;
SerialIO->io_Baud = 4800L; /* Baud Rate */
SerialIO->io_ReadLen = SerialIO->io_WriteLen = 8; /* Bits */
SerialIO->io_StopBits = 2; /* Stop-Bits */
DoIO((struct IORequest *)SerialIO);
/*************************************************************************/
Delay(7L);
SerialIO->IOSer.io_Command = CMD_WRITE;
SerialIO->IOSer.io_Length = 5;
SerialIO->IOSer.io_Data = (APTR)SerialBuffer;
DoIO((struct IORequest *)SerialIO);
}/* Serial_Write() end */
LONG Freq_to_Buffer(LONG freq) /* Frequenz in die 4 Bytes umrechnen */
{
int b1, b2, b3, b4, b5 = 1;
int zehner, liByte, reByte = 1;
/* Frequency limits for FTZ-equipment */
if (freq < 150000L) freq = 150000L;
else if(freq < 100000000L)
{
if(freq > 29999900L) freq = 29999900L;
}
else
{
if (freq < 144000000L) freq = 144000000L;
else if(freq > 146000000L) freq = 146000000L;
}
zehner = (int)(freq % 100L);
if (zehner < 13) {reByte = 1; freq = freq / 100L * 100L + 0L;}
else if(zehner < 38) {reByte = 2; freq = freq / 100L * 100L + 25L;}
else if(zehner < 68) {reByte = 4; freq = freq / 100L * 100L + 50L;}
else if(zehner < 88) {reByte = 8; freq = freq / 100L * 100L + 75L;}
else freq = freq / 100L * 100L + 100L;
liByte = (int)((freq % 1000L) / 100L); /* 100 Hz */
b1 = (liByte << 4) | reByte;
b2 = (int)((freq % 100000L) / 1000L);
b3 = (int)((freq % 10000000L) / 100000L);
b4 = (int)((freq % 1000000000L) / 10000000L);
b2 = ((b2 / 10) << 4) + b2 % 10; /* Umwandeln : Hex -> Dez */
b3 = ((b3 / 10) << 4) + b3 % 10;
b4 = ((b4 / 10) << 4) + b4 % 10;
sprintf((char*)SerialBuffer, "%1c%1c%1c%1c%1c", b1, b2, b3, b4, b5);
return(freq);
}/* Freq_to_Buffer() end */
void Set_Freq(LONG freq) /* Frequenz einstellen und Werte auslesen */
{
float S_wert = 0.0F;
LONG frequenz;
int i, squelch;
frequenz = Freq_to_Buffer(freq);
printf("Freq.: %9ld Hz %02x H %02x H %02x H %02x H %02x H ", frequenz,
SerialBuffer[0],SerialBuffer[1],SerialBuffer[2],SerialBuffer[3],SerialBuffer[4]);
Serial_Write();
Serial_Read();
/* S-Wert: Mittelwert aus der Anzahl der empfangenen Messwerte */
for(i = 0; i < MAX(1,SerialIO->IOSer.io_Length); i++)
S_wert+=((float)(SerialBuffer[i] & 63) / 4.0F);
S_wert/=MAX(1.0F, (float)SerialIO->IOSer.io_Length);
/* Squelch erst beim 2ten Wert ([1]) ermitteln, da der erste Wert unzuverlässig ist */
squelch = ((SerialBuffer[1] & 64) >> 6);
if(S_wert > 9.25F)
printf("S-Meter: 9 +%2d SQ: %d\n", (int)(((S_wert-9.0F) * 10.0F)+2.5F)/5*5, squelch);
else
printf("S-Meter: %d SQ: %d\n", (int)S_wert, squelch);
}/* Set_Freq() end */